package mo.leetcode_top;

import java.util.ArrayList;
import java.util.List;

public class L22 {

    private List<String> res = new ArrayList<>();

    public List<String> generateParenthesis(int n) {
        helper(n, n, "", res);
        return res;
    }

    private void helper(int left, int right, String s, List<String> res) {
        if (left < 0 || right < 0 || left > right) {
            return;
        }
        if (left == 0 && right == 0) {
            res.add(s);
            return;
        }
        helper(left-1, right, s+"(", res);
        helper(left, right-1, s+")", res);
    }

}
